import { Message } from 'element-ui'
export function setRouterAuth(router) {
  const publicRouter = ['/login', '/register']
  router.beforeEach((to, from, next) => {
    if (publicRouter.includes(to.path)) {
      return next()
    }
    const token = localStorage.getItem('Authorization')
    if (!token) {
      Message({
        message: '请先登录'
      })
      next('/login')
    } else {
      next()
    }
  })
  return router.beforeEach
}
